package gugu.services.dao.impl;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.data.mongodb.core.MongoOperations;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Repository;
import static org.springframework.data.mongodb.core.query.Query.query;
import static org.springframework.data.mongodb.core.query.Update.update;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import gugu.domain.User;
import gugu.services.dao.UserDao;

@Repository("userServiceDaoMongo")
public class UserDaoMongoImpl extends CrudDaoMongoImpl<User> implements UserDao{
	
	private static final Log LOGGER = LogFactory.getLog(MongoTemplate.class);
	
	@Resource
	private MongoOperations mongoOpts;
	
	@Override
	public void saveUser(User user) {
		super.saveOrUpdate(user);
	}

	@Override
	public boolean deleteUser(User user) {
			return super.delete(user);
	}

	@Override
	public User findUser(String userGuid) {
		return super.find(userGuid, User.class);
	}

	@Override
	public User findUserByAccount(String contactEmail) {
		return  mongoOpts.findOne(query(where("contactEmail").is(contactEmail)),User.class);
	}

	@Override
	public void insertUser(User user) {
		super.insert(user);
	}

	@Override
	public void updateUser(User user) {
		super.saveOrUpdate(user);
	}

}
